<template>
  <div class="error-container">
    <div class="error-content">
      <div class="error-icon">
        <i class="fas fa-exclamation-triangle"></i>
      </div>
      <h3 class="error-title">出现了一些问题</h3>
      <p class="error-message">{{ message }}</p>
      <div class="error-actions">
        <button class="retry-btn" @click="$emit('retry')">
          <i class="fas fa-redo"></i>
          重试
        </button>
        <button class="home-btn" @click="goHome">
          <i class="fas fa-home"></i>
          返回首页
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'

defineProps({
  message: {
    type: String,
    default: '加载内容时发生错误，请稍后重试'
  }
})

defineEmits(['retry'])

const router = useRouter()

const goHome = () => {
  router.push('/')
}
</script>

<style scoped>
.error-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  margin: var(--space-lg) 0;
  border: 1px solid var(--color-error-light);
}

.error-content {
  text-align: center;
  max-width: 400px;
  padding: var(--space-xl);
}

.error-icon {
  font-size: var(--font-size-4xl);
  color: var(--color-error);
  margin-bottom: var(--space-lg);
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.error-title {
  color: var(--text-primary);
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  margin: 0 0 var(--space-md);
}

.error-message {
  color: var(--text-secondary);
  font-size: var(--font-size-md);
  line-height: var(--line-height-relaxed);
  margin: 0 0 var(--space-xl);
}

.error-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
}

.retry-btn,
.home-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.retry-btn {
  background: var(--color-primary);
  color: var(--text-inverse);
}

.retry-btn:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.home-btn {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

.home-btn:hover {
  background: var(--bg-tertiary);
  transform: translateY(-1px);
}

@media (prefers-reduced-motion: reduce) {
  .error-icon {
    animation: none;
  }
}
</style> 